<?php 
/**
 * @version        $Id$
 * @author         master@xuewl.com
 * @copyright      Copyright (c) 2007 - 2014, Chongqing xuewl Information Technology Co., Ltd.
 * @link           http://www.xuewl.com
**/
namespace Member\Controller;
use \Member\Controller\InitController;
class SmsController extends InitController {
	
	public function _initialize() {
		parent::_initialize();
		$this->$sms_db=D('Sms_report');
		$this->db = D('Member');
	}

	
	public function index() {
		$this->getCode($msg,$type);
	}
	
	public function code($msg,$type){
		$infos=I('post.');
		$userinfo=$this->db->where(array('userid'=>$this->userid))->find();
		$act=$infos['act'];
		$code=random(6,1);
		$info['id_code']=$code;
		$info['userid']=$this->userid;
		$info['msg']=$msg.$code;
		$info['posttime'] = time();
		$info['status']=$userinfo['status'];
		$info['mobile']=$userinfo['mobile'];
		$info['enum']=$type;
		
		if ($act=='getCode'){
			//发送手机短信验证码
		$getcode=$this->sms_db->add($info);
		if ($getcode){	
		$sms = new \Sms\Api\SmsApi();
     	$pay=$sms->send($userinfo['mobile'],$info['msg']);
		if (!$pay){
				$data['flag']=0;
				$data['msg']="发送失败！";
				echo json_encode($data);
			}else{
				$data['flag']=1;
				$data['msg']="发送成功！";
				echo json_encode($data);
			}
		}
		
		}
	}
}